package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.OrderDetail;
import com.sky.entity.SetmealDish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     *
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);


    /**
     * 新增菜品并返回主键
     */
    @Insert("INSERT INTO dish (name, category_id, price, image, description, create_time, update_time, create_user,update_user, status)" +
            "values (#{name}, #{categoryId}, #{price}, #{image}, #{description}, #{createTime}, #{updateTime}, #{createUser},#{updateUser}, #{status})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    @AutoFill(OperationType.INSERT)
    void insert(Dish d);

    /**
     * 查询 id 对应的菜品
     */
    @Select("SELECT * FROM dish WHERE id =#{id}")
    Dish getById(String id);


    /**
     * 根据分类id查询菜品
     * */
    @Select("SELECT * FROM  dish WHERE category_id =#{id}")
    List<Dish> IdDishesByCategory(Long id);


    @Select("SELECT * FROM  dish WHERE id = #{id}")
    List<SetmealDish> IdDSetmealDish(Long id);




    /**
     * 菜品分页查询
     */
    List<DishVO> page(DishPageQueryDTO dishPageQueryDTO);


    /**
     * 批量删除菜品
     */
    void deleteDish(String[] idArray);



    /**
     *  修改菜品
     * */
    @AutoFill(value = OperationType.UPDATE)
    void update(Dish dish);


    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);


}
